import 'package:xiecheng_lvyou/model/common_model.dart';
import 'package:xiecheng_lvyou/model/config_model.dart';
import 'package:xiecheng_lvyou/model/grid_nav_model.dart';
import 'package:xiecheng_lvyou/model/sales_box_model.dart';

class HomeModel {
  ConfigModel? config;
  List<CommonModel>? bannerList;
  List<CommonModel>? localNavList;
  List<CommonModel>? subNavList;
  GridNavModel? gridNav;
  SalesBoxModel? salesBox;

  HomeModel(
      {this.config,
      this.bannerList,
      this.localNavList,
      this.subNavList,
      this.gridNav,
      this.salesBox});

  HomeModel.fromJson(Map<String, dynamic> json) {
    config = ConfigModel.fromJson(json['config']);

    var bannerListJson = json['bannerList'] as List;
    bannerList = bannerListJson.map((i) => CommonModel.fromJson(i)).toList();

    var localNavListJson = json['localNavList'] as List;
    localNavList =
        localNavListJson.map((i) => CommonModel.fromJson(i)).toList();

    var subNavListJson = json['subNavList'] as List;
    subNavList = subNavListJson.map((i) => CommonModel.fromJson(i)).toList();

    gridNav = GridNavModel.fromJson(json['gridNav']);

    salesBox = SalesBoxModel.fromJson(json['salesBox']);
  }

  Map<String, dynamic> toJson() {
      final Map<String, dynamic> data = <String, dynamic>{};

      if (config != null) {
        data['config'] = config!.toJson();
      }
    
      if (bannerList != null) {
        data['bannerList'] = bannerList!.map((i) => i.toJson()).toList();
      }

      if (localNavList != null) {
        data['localNavList'] = localNavList!.map((i) => i.toJson()).toList();
      }
      
      if (subNavList != null) {
        data['subNavList'] = subNavList!.map((i) => i.toJson()).toList();
      }

      if (gridNav != null) {
        data['gridNav'] = gridNav!.toJson();
      }

      if (salesBox != null) {
        data['salesBox'] = salesBox!.toJson();
      }
      
      return data;
  }

}
